home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / objc.557 < prev    next >
Text File  |  1992-02-06  |  1KB  |  41 lines

  1. {\rtf0\ansi{\fonttbl\f3\fnil Times-Roman;\f0\fmodern Courier;}
  2. \paperw11760
  3. \paperh7200
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f3\b0\i0\ul0\fs28 perform return value float\
  8. \
  9. Q:  I am trying to perform a method that returns a float.  In the Concepts manual, page 3-20, it indicates I can just cast the return value to float like this:\
  10. \
  11.  
  12. \f0\fs24     float    myGray;\
  13.     myGray = (float)[textField perform:@selector(backgroundGray)];\
  14.     \
  15.  
  16. \f3\fs28 But I get a compile-time error of "pointer value used where a float was expected."  What can I do?\
  17. \
  18. A:   The 
  19. \b perform
  20. \b0  method is prototyped to return a value of type 
  21. \b id
  22. \b0 .  While the C compiler lets you cast of lot of things, it says enough is enough when you try cast somethig of type 
  23. \b id
  24. \b0  to be 
  25. \b float
  26. \b0 .  Here is one workaround which will allow you to get the value you want:\
  27. \
  28.  
  29. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f0\fs24\fc0     id myId;\
  30.     float myGray;\
  31.     myId = [textField perform:@selector(backgroundGray)];\
  32.     myFloat = *(float *)&myId;\
  33.  
  34. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f3\fs28 \
  35. Valid for 1.0\
  36. Valid for 2.0\
  37. \
  38. QA557\
  39. \
  40.  
  41.